package org.aileen.springioc.demo;

import org.aileen.springioc.demo.controller.UserController;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;

//@ComponentScan("org.aileen.springioc.demo")
@SpringBootApplication
public class SpringIocApplication {

	public static void main(String[] args) {
		ApplicationContext context = SpringApplication.run(SpringIocApplication.class, args);
//		//--------------------获取重命名后的对象
//		UserInfo bean =  context.getBean("o1",UserInfo.class);
//		System.out.println(bean);
//
//		UserInfo bean2 =  context.getBean("userInfo2",UserInfo.class);
//		System.out.println(bean2);

//		UserConfig bean2 = context.getBean("userConfig",UserConfig.class);
//		bean2.sayHi();
		//---------------------------------------------
//		UserInfo bean = context.getBean("userInfo",UserInfo.class);
//		System.out.println(bean);
		//------------------
//		UserConfig userConfig = context.getBean(UserConfig.class);
//		userConfig.sayHi();
//		//------------------
//		UserComponent userComponent = context.getBean(UserComponent.class);
//		userComponent.sayHi();
		//------------------
//		UserRepository userRepository = context.getBean(UserRepository.class);
//		userRepository.SayHi();
//		//---------------------------------------------
//		//根据类型获取Bean
//		UserService userService = context.getBean(UserService.class);
//		System.out.println(userService);
//		//---------------------------------------------
//		//根据名称获取Bean
//		UserService userService2 = (UserService) context.getBean("userService");
//		System.out.println(userService2);
//		//---------------------------------------------
//		//根据类型和名称获取Bean -> 相当于双重保险
//		UserService userService3 = (UserService) context.getBean("userService",UserService.class);
//		System.out.println(userService3);
		//----------------------------------------------------------
//		//获取注解存储对象的步骤
//		//①获取存储对象的容器->应用程序上下文
//		ApplicationContext context = SpringApplication.run(SpringIocApplication.class, args);
		//获取controller注解存储的Spring对象bean
		UserController bean = context.getBean(UserController.class);//②获取容器中存储的对象
		System.out.println(bean);
		bean.sayHi();
		//---------------------------------------------
//		//获取service注解存储的Spring对象bean
//		UserService userService = context.getBean(UserService.class);
//		userService.sayHi();

	}
}
